package com.hy.mydesktop.client.component.factory;

import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.hy.mydesktop.client.component.meta.AbstractComponetModelEnum;
import com.hy.mydesktop.client.component.meta.ToolBarModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.ItemOfAssociateToWindow;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-8-29；时间：下午04:17:16</li>
 * <li>类型名称：ToolBarFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class ToolBarFactory {
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建工具栏控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午04:19:39</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaModel
	 * @return
	 */
	public static ToolBar createToolBar(GxtComponentMetaNodeModel gxtComponentMetaModel){
		return configureToolBar(gxtComponentMetaModel);
		
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：配置工具栏属性值</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午04:21:41</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static ToolBar configureToolBar(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		
		ToolBar bar=createDefaultToolBar();
		bar = AbstractComponetFactory.configureAbstractComponet(bar, gxtComponentMetaNodeModel);
		
		//添加子控件
		if(gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.CHILDREN_ITEMS)!=null){		
			List<ItemOfAssociateToWindow> list =(List<ItemOfAssociateToWindow>)gxtComponentMetaNodeModel.get(ComponentMetaDataConstants.CHILDREN_ITEMS);
		    for(int i=0;i<list.size();i++){
					Button button=ButtonFactory.createItemOfAssociateToWindow(list.get(i));
					
					bar.add(button);
			}			
		}else {
			if(gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase())!=null){
				//添加子控件
			 List<GxtComponentMetaNodeModel> list =(List<GxtComponentMetaNodeModel>)gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase());
			 for(int i=0;i<list.size();i++)
				{
					Button button=ButtonFactory.createButton(list.get(i));
					
					bar.add(button);
				}			
			}
		}
		
		
		
		if(gxtComponentMetaNodeModel.get(ToolBarModelEnum.ADD.name().toLowerCase())!=null){
			List<String> list=(List<String>)gxtComponentMetaNodeModel.get(ToolBarModelEnum.ADD.name().toLowerCase());
			
			for(String i:list){
				Button b=new Button(i);
				bar.add(b);
			}
			
			//bar.add((Component)gxtComponentMetaModel.get(ToolBarModelEnum.ADD.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(ToolBarModelEnum.ALIGN.name().toLowerCase())!=null){
			
			bar.setAlignment((HorizontalAlignment)gxtComponentMetaNodeModel.get(ToolBarModelEnum.ALIGN.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(ToolBarModelEnum.SPACING.name().toLowerCase())!=null){
			
			bar.setSpacing((Integer)gxtComponentMetaNodeModel.get(ToolBarModelEnum.SPACING.name().toLowerCase()));
		}
		
		
		
		return bar;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建默认的工具栏控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午04:22:54</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	private static ToolBar createDefaultToolBar()
	{
		ToolBar bar=new ToolBar();
		//bar.add(new Button("文件"));
		
		return bar;
	}
}
